<%--
  Created by IntelliJ IDEA.
  User: lw
  Date: 2021/6/28
  Time: 13:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="<c:url value="/static/css/font.css"/>">
    <link rel="stylesheet" href="<c:url value="/static/css/xadmin.css"/>">
    <script type="text/javascript" src="<c:url value="/static/lib/layui/layui.js"/>" charset="utf-8"></script>
    <script type="text/javascript" src="<c:url value="/static/js/xadmin.js"/>"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="addform">
            <div class="layui-form-item">
                <label for="uid" class="layui-form-label">
                    <span class="x-red">*</span>id
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="uid" name="uid" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="loginname" class="layui-form-label">
                    <span class="x-red">*</span>登录名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="loginname" name="loginname" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="password" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="password" name="password" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男" checked>
                    <input type="radio" name="sex" value="女" title="女">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="tel" class="layui-form-label">
                    手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="tel" name="tel" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="birthday" class="layui-form-label">
                    出生日期
                </label>
                <div class="layui-input-inline">
                    <input type="date" id="birthday" name="birthday" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
            </div>
        </form>
    </div>
</div>

<script>

    layui.use(['form', 'layer', 'jquery'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            // //自定义验证规则
            // form.verify({
            //     nikename: function (value) {
            //         if (value.length < 5) {
            //             return '昵称至少得5个字符啊';
            //         }
            //     },
            //     pass: [/(.+){6,12}$/, '密码必须6到12位'],
            //     repass: function (value) {
            //         if ($('#L_pass').val() != $('#L_repass').val()) {
            //             return '两次密码不一致';
            //         }
            //     }
            // });

            //监听提交
            form.on('submit(add)',
                function (data) {
                    console.log(data);
                    //发异步，数据提交
                    $.ajax({
                        type:"post",
                        url:"<c:url value="/userAddServlet" />",
                        data:$('#addform').serialize(),
                        success: function(result){
                            // alert("POST请求到的数据：" + result);
                            if (result === "true"){
                                layer.alert("增加成功", {
                                        icon: 6
                                    },
                                    function () {
                                        //关闭当前frame
                                        xadmin.close();

                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }else {
                                layer.alert("增加失败", {
                                        icon: 6
                                    },
                                    function () {
                                        //关闭当前frame
                                        xadmin.close();

                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }
                        }
                    })

                    return false;
                });
        });
</script>
</body>
</html>
